package effects.post
{
	import flash.filters.BlurFilter;
	import flash.geom.Point;
	import flash.display.BlendMode;
	import flash.display.BitmapData;
	import evo.engine.AbstractPostProcessor;
	
	public class BloomEffect extends AbstractPostProcessor
	{		
		private var bloomer:BlurFilter;
		private var orig:Point;
		private var t:BitmapData;
		
		public override function init(params:Object=null):void
		{	
			bloomer = new BlurFilter(8,8,1);
			orig = new Point(0,0);
			super.init(params);
		}
		
		public override function set output(buffer:BitmapData):void
		{
			super.output = buffer;
			t = new BitmapData(buffer.width, buffer.height,false,0);
			defaultInput();
		}
			
		public override function play(dt:Number):void
		{
				_input.lock();
				_input.fillRect(_input.rect,0);
				super.play(dt);
				_input.unlock();
				buffer.lock();							

				t.lock();
				t.applyFilter(_input,buffer.rect, orig, bloomer);
				t.unlock();
				buffer.draw(t, null,null,BlendMode.ADD);
				
				t.lock();
				t.applyFilter(t,buffer.rect, orig, bloomer);
				t.unlock();
				buffer.draw(t, null,null,BlendMode.ADD);

				t.lock();
				t.applyFilter(t,buffer.rect, orig, bloomer);
				t.unlock();
				buffer.draw(t, null,null,BlendMode.ADD);

				buffer.draw(_input,null, null, BlendMode.ADD);
				buffer.unlock();
		};
	}
}